package com.cyt.web.controller.sys;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.sys.model.po.ParamConfig;
import com.cyt.sys.model.vo.SysParamConfigVo;
import com.cyt.sys.service.SysParamConfigService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2019/3/6.
 * 参数配置控制层
 */
@RestController
public class SysParamConfigController extends SysBaseController {

    @Resource
    private SysParamConfigService sysParamConfigService;

    /**
     * 系统模块统一跳转处理
     *
     * @param model
     * @return
     */
    @RequestMapping("/sys/paramConfig/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * @Author: QianJin
     * @Date: 2019-03-06 14:19
     * @Description: 分页查询，page:当前页面，limit:页面大小
     */
    @BaseLog(module = "系统管理", classz = "参数配置", methods = "分页查询", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/paramConfig/page", method = RequestMethod.POST)
    public ReturnResult page(ParamConfig paramConfig, int limit, int page) {
        ReturnResult returnResult = sysParamConfigService.page(paramConfig, limit, page);
        return returnResult;
    }

    /**
     * 删除某一条记录
     *
     * @param id
     * @return
     */
    @BaseLog(module = "系统管理", classz = "参数配置", methods = "删除", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/paramConfig/delete", method = RequestMethod.GET)
    public ReturnResult delete(String id) {
        ReturnResult result = sysParamConfigService.deleteById(id);
        return result;
    }

    /**
     * @author: QianJin
     * @date: 2019/03/07 8:58
     * @Description: 保存/更新参数配置
     */
    @BaseLog(module = "系统管理", classz = "参数配置", methods = "保存/更新参数配置", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/paramConfig/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(SysParamConfigVo sysParamConfigVo) {
        ReturnResult result = sysParamConfigService.addOrUpdate(sysParamConfigVo);
        return result;
    }

    /**
     * @author: QianJin
     * @date: 2019/03/06 16:01
     * @Description: 跳转角色编辑页面
     */
    @RequestMapping(value = "/paramConfig/getAddOrEdit", method = RequestMethod.GET)
    public ModelAndView getAddOrEdit(String id) {
        ModelAndView view = new ModelAndView("/sys/paramConfig/paramConfigEdit");
        if (id != null && !"".equals(id)) {
            ParamConfig paramConfig = sysParamConfigService.selectParamConfigId(id);
            view.addObject("paramConfig", paramConfig);
        }
        return view;
    }
}